﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthByDesign.Domain.Panels;

namespace MyHealthByDesign.Domain
{
    public class Question
    {
        #region variables
        
        #endregion

        #region Properties

        public int Id { get; set; }
        public int Category { get; set; }
        public int SortOrder { get; set; }
        public string DisplayType { get; set; }
        public string Name { get; set; }
        public string ContentLabel { get; set; }
        public string FieldCSS { get; set; }
        public string FieldSuffix { get; set; }
        public string FieldHelpText { get; set; }
        public string FieldHelpURL { get; set; }
        public List<QuestionOption> FieldOptions { get; set; }

        #endregion


        #region Methods

        // This method calls the IQuestionPanel routine for the DisplayType related class
        // to create an ASP.NET Panel to place on a page to render the question.
        public Panel DisplayQuestion()
        {
            return DetermineQuestionPanel().GenerateQuestionDisplay(this);
        }

        // This method calls the IQuestionPanel routine for the DisplayType related class
        // to retrieve the entered value for this questions when rendered to a page.
        public Dictionary<Question, NameValueCollection> RetrieveQuestionValues(ContentPlaceHolder cph)
        {
            return DetermineQuestionPanel().RetrieveQuestionValue(this, cph);
        }

        // shared method to determine Type and create appropriate class type that implements IQuestinoPanel
        private IQuestionPanel DetermineQuestionPanel()
        {
            Type typField = typeof(IQuestionPanel).Assembly.GetType(DisplayType);
            IQuestionPanel iqp = (IQuestionPanel)Activator.CreateInstance(typField);

            return iqp;
        }

        #endregion
    }
}